package com.indeep.user.controller.base;

import com.indeep.user.service.base.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

public class BaseController<T, S extends BaseService<T>> {

    protected S service;

    public BaseController(S ser) {
        this.service = ser;
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取列表", notes = "获取列表")
    public List<T> list() {
        return service.list();
    }



    @PostMapping("/save")
    @ApiOperation(value = "新增数据", notes = "新增数据")
    public boolean save(@RequestBody T entity) {
        if (entity == null) {
            //  throw new HttpMessageNotReadableException("请求体不能为空", null);
        }
        return service.save(entity);
    }

    @PostMapping("/update")
    @ApiOperation(value = "根据id修改数据", notes = "根据id修改数据")
    public boolean update(@RequestBody T entity) {
        return service.updateById(entity);
    }

    @PutMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除数据", notes = "根据id删除数据")
    public boolean delete(@PathVariable Long id) {
        return service.removeById(id);
    }

    @GetMapping("/get/{id}")
    @ApiOperation(value = "根据id获取数据", notes = "根据id删除数据")
    public T getById(@PathVariable Long id) {
        return service.getById(id);
    }
}